package com.yyfax.pay.order.data.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.yyfax.commons.lang.DateUtil;
import com.yyfax.framework.service.CacheService;
import com.yyfax.framework.service.impl.BaseServiceImpl;
import com.yyfax.pay.order.data.dao.PayoutBatchOrderLogDao;
import com.yyfax.pay.order.data.service.PayoutBatchOrderLogService;
import com.yyfax.pay.order.model.po.PayoutBatchOrderLogPO;

/**
 * 批量代付日志服务实现
 *
 * @author buyi
 * @date 2017-04-12 11:09:15
 * @since 1.0.0
 */
@Service
public class PayoutBatchOrderLogServiceImpl extends BaseServiceImpl implements PayoutBatchOrderLogService {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private PayoutBatchOrderLogDao payoutBatchOrderLogDao;

	public PayoutBatchOrderLogServiceImpl(@Qualifier("payCacheService") CacheService cacheService) {
		super(cacheService);
	}

	@Override
	public PayoutBatchOrderLogPO queryByIdAndMerchantCode(int id, String merchantCode) throws Exception {
		if (id <= 0 && StringUtils.isBlank(merchantCode)) {
			logger.debug("参数 'id' 不能为0，且 'merchantCode' 不能为空 ");
			return null;
		}

		return payoutBatchOrderLogDao.selectByIdAndMerchantCode(id, merchantCode);
	}

	@Override
	public List<PayoutBatchOrderLogPO> queryListByPayoutBatchOrderId(String merchantCode, String payoutBatchOrderId) {
		if (StringUtils.isBlank(merchantCode) && StringUtils.isBlank(payoutBatchOrderId)) {
			logger.debug("参数 payoutBatchOrderId/merchantCode 为空 ");
			return null;
		}

		return payoutBatchOrderLogDao.selectListByPayoutBatchOrderId(merchantCode, payoutBatchOrderId);
	}

	@Override
	public int save(PayoutBatchOrderLogPO po) throws Exception {
		if (po == null) {
			logger.debug("参数po为空，返回-1");
			return 0;
		}

		po.setCreateTime(DateUtil.getCurrentDateTime());

		return payoutBatchOrderLogDao.insert(po);
	}

}
